package org.example.azkaban.demo.api;

import org.example.azkaban.demo.response.*;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * Azkaban接口定义
 *
 * @author 01
 */
public interface AzkabanApi {

    /**
     * 登录
     *
     * @return see {@link LoginResponse}
     * @throws IOException IOException
     */
    LoginResponse login() throws IOException;

    /**
     * 创建Project
     *
     * @param name 项目名称
     * @param desc 项目描述
     * @return see {@link BaseResponse}
     */
    BaseResponse createProject(String name, String desc);

    /**
     * 上传zip包
     *
     * @param filePath    文件路径
     * @param projectName 项目名称
     * @return see {@link ProjectZipResponse}
     */
    ProjectZipResponse uploadProjectZip(String filePath, String projectName);

    /**
     * 获取Project下的flows
     *
     * @param projectName 项目名称
     * @return see {@link FetchFlowsResponse}
     */
    FetchFlowsResponse fetchProjectFlows(String projectName);

    /**
     * 删除Project
     *
     * @param name 项目名称
     * @return see {@link BaseResponse}
     */
    BaseResponse deleteProject(String name);

    /**
     * 执行flow
     *
     * @param projectName 项目名称
     * @param flowName    流程名称
     * @return see {@link ExecFlowResponse}
     */
    ExecFlowResponse executeFlow(String projectName, String flowName);

    /**
     * 获取flow执行结果
     *
     * @param execId 执行id
     * @return see {@link FetchExecFlowResponse}
     */
    FetchExecFlowResponse fetchExecFlow(String execId);

    /**
     * 获取flow的执行日志
     *
     * @param execId 执行id
     * @param jobId  任务id
     * @param offset 偏移量
     * @param length 长度
     * @return see {@link FetchExecJobLogs}
     */
    FetchExecJobLogs fetchExecJobLogs(String execId, String jobId,
                                      int offset, int length);

    /**
     * 调度flow
     *
     * @param projectName    项目名称
     * @param flowName       流程名称
     * @param cronExpression cron表达式
     * @return see {@link ScheduleCronFlowResponse}
     * @throws UnsupportedEncodingException UnsupportedEncodingException
     */
    ScheduleCronFlowResponse scheduleCronFlow(String projectName,
                                              String flowName,
                                              String cronExpression) throws UnsupportedEncodingException;

    /**
     * 删除调度
     *
     * @param scheduleId 调度id
     * @return see {@link BaseResponse}
     */
    BaseResponse removeSchedule(String scheduleId);

    /**
     * 取消flow
     *
     * @param execId 执行id
     * @return see {@link BaseResponse}
     */
    BaseResponse cancelFlow(String execId);
}
